package com.baidu.service.imp;

import com.baidu.controller.WycNoteController;
import com.baidu.entity.*;
import com.baidu.mapper.*;
import com.baidu.service.CreditService;
import com.baidu.utils.Result;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/**
 * @author 田甜
 * @version 1.0
 * @description: TODO
 * @date 2021/12/13 0013 8:44
 */
@Service
@Component
@Slf4j
public class CreditServiceImp implements CreditService {
    @Autowired
    private TbyRegisterMapper tbyRegisterMapper;//登录表
    @Autowired
    private TbyJudgmentMapper tbyJudgmentMapper;//额度积分表
    @Autowired
    private TbyIdentityMapper tbyIdentityMapper;//用户信息表
    @Autowired
    private TbyBankcardMapper tbyBankcardMapper;//银行卡表
    @Autowired
    private TbyContcatmationMapper tbyContcatmationMapper;//联系人表

    @Override
    public Result login(TbyRegister tbyRegister)  throws IOException{

        QueryWrapper<TbyRegister> Wrapper = new QueryWrapper<>();
        //Wrapper.eq("loginname",tbyRegister.getLoginname()).eq("password",tbyRegister.getPassword());
        QueryWrapper<TbyRegister> wrapperpassword = new QueryWrapper<>();
        wrapperpassword.eq("password", tbyRegister.getPassword());
        TbyRegister loginname = tbyRegisterMapper.selectOne(Wrapper.eq("loginname", tbyRegister.getLoginname()));
        TbyRegister password = tbyRegisterMapper.selectOne(Wrapper.eq("password", tbyRegister.getPassword()));
        HashMap<String, Object> HashMap = new HashMap<>();
        //查询密码
        if (loginname != null&&password!=null) {
            if (loginname.getLoginname().equals(loginname.getLoginname())) {
                //判断密码是不是null
                if (password.getPassword().equals(tbyRegister.getPassword())) {
                    HashMap.put("user",loginname);
                    TbyJudgment tbyJudgment = tbyJudgmentMapper.selectById(loginname.getId());
                    HashMap.put("userdetaio",tbyJudgment);
                    TbyIdentity tbyIdentity = tbyIdentityMapper.selectById(loginname.getId());
                    HashMap.put("idCard",tbyIdentity.getId());
                    return new Result(true, 20000, "登录成功", HashMap);
                }
            }
        }
        //账号错误
        return new Result(false, 20002, "登录失败请检查账号或密码错误", null);
    }

    @Override
    public void capled(TbyRegister tbyRegister, Map map) {
        String loginname = tbyRegister.getLoginname();
        String iphone = tbyRegister.getIphone();
        //String roleCode = tbyRegister.getRoleCode();
        map.put("code",1);
        map.put("phone",iphone);
        map.put("message",loginname);
        log.info("{}短信接口需要:",map);
        Integer id = tbyRegister.getId();
        System.out.println(id);
        //生成对应的用户信息表
        //添加登录的信息
        tbyRegisterMapper.insert(tbyRegister);
    }



}
